// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import 'view-design/dist/styles/iview.css';
import ViewUI from 'view-design';
Vue.use(ViewUI);

import leafletPlugs from './plugins/leaflet'
Vue.use(leafletPlugs);

import less from 'less'
Vue.use(less)

import axios from 'axios'  // 安装axios后引入
Vue.prototype.$axios = axios  // 将axios挂载到原型上方便使用


/* leaflet icon */
delete L.Icon.Default.prototype._getIconUrl
L.Icon.Default.mergeOptions({
  iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
  iconUrl: require('leaflet/dist/images/marker-icon.png'),
  shadowUrl: require('leaflet/dist/images/marker-shadow.png')
})

import 'leaflet-draw/dist/leaflet.draw.css'

import MetaInfo from 'vue-meta-info'
Vue.use(MetaInfo);

import './assets/utils';
import { isMobile, isWeiXin } from './assets/utils';

import MuseUI from 'muse-ui';
import 'muse-ui/dist/muse-ui.css';

Vue.use(MuseUI);
import 'typeface-roboto';

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  created () {
    if (isMobile() || isWeiXin()) {
      this.$router.replace('/');
    } else {
      this.$router.replace('/pc');
    }
  },
  mounted () {
    document.dispatchEvent(new Event('render-event'));
  }
})

var _hmt = _hmt || [];
window._hmt = _hmt; // 修改为window 全局变量
 (function () {
       var hm = document.createElement("script");
       hm.src = "https://hm.baidu.com/hm.js?4e17e01d717bfbd942a2cce3e9c060dc";
       var s = document.getElementsByTagName("script")[0];
       s.parentNode.insertBefore(hm, s);
  })();

// 加入百度统计
router.beforeEach((to, from, next) => {
  if (to.path) {
    if (window._hmt) {
      window._hmt.push(['_trackPageview', '/#' + to.fullPath])
    }
  }
  next()
})